﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FeatureModelCore.FMTypes;
using Collections.TreeCollections;
using FeatureModelCore.FMCrossTreeConstraint;
using FeatureModelCore.FMInterface;
using Collections;

namespace FeatureModelCore.Optimized
{
    public class OptimizedConstraint : IConstraint, IOptimizable
    {
        public TreeNodeIdentify ID { get { return _standardCons.ID; } }
        public FMCrossTreeConstraintType Type { get { return _standardCons.Type; } }
        public TreeNodeIdentify NodeIDA { get { return _standardCons.NodeIDA; } }
        public TreeNodeIdentify NodeIDB { get { return _standardCons.NodeIDB; } }
        public IFeature NodeA { get { return _nodeA; } }
        public IFeature NodeB { get { return _nodeB; } }
        public Tree Tree { get { return _tree; } }
        public IFeatureModelObject StandardFeatureObject { get { return _standardCons; } }

        private CrossTreeConstraint _standardCons;
        private OptimizedFeatureModel _tree;
        private TreeNodeIdentify _id;
        private IOptimizableFeature _nodeA;
        private IOptimizableFeature _nodeB;

        public OptimizedConstraint(OptimizedFeatureModel tree, CrossTreeConstraint standardCons)
        {
            _tree = tree;
            _standardCons = standardCons;
            _id = standardCons.ID;

            _nodeA = OptimizedFeatureModel.GetTransferNodeInTree(tree, standardCons.NodeIDA);
            _nodeB = OptimizedFeatureModel.GetTransferNodeInTree(tree, standardCons.NodeIDB);
        }

        public override string ToString()
        {
            return string.Format("{0} {1} {2}", NodeA
                , Type.ToString()
                , NodeB);
        }
    }
}
